package com.jason.canvas.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

/**
 * @DESC: Path的使用
 *
 *  rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
    rLineTo(float dx, float dy)
    rMoveTo(float dx, float dy)
    rQuadTo(float dx1, float dy1, float dx2, float dy2)

    这一系列rXXXTo方法其实跟上面的那些XXXTo差不多的，唯一的不同是rXXXTo方法的参考坐标是相对的而XXXTo方法的参考坐标始终是参照画布原点坐标

 * @Author: Jason
 * @Date: 16/9/19
 * @Time: 11:42
 */

public class PathView9 extends View {

    private Path mPath;
    private Paint mPaint;



    public PathView9(Context context, AttributeSet attrs) {
        super(context, attrs);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.CYAN);
        mPaint.setStrokeWidth(5);

        mPath = new Path();
        // 移动点 [100,100]
        mPath.moveTo(100, 100);

        // 连接路径
        //mPath.lineTo(200, 200); // 已canvas画布原点[0,0]开始
        mPath.rLineTo(200, 200);// 相对 + moveTo的[100,100] 相当于画布的[300,300]位置
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawPath(mPath, mPaint);
    }
}
